package com.msmall.community.common.action.html;

import java.util.Date;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantAjax;
import com.msmall.base.util.ConstantDB;
import com.msmall.base.util.ConstantUrl;
import com.msmall.base.util.Constants;
import com.msmall.community.common.model.Abuse;
import com.msmall.community.common.service.AbuseManager;

public class AbuseAction extends HTMLBaseAction{

	private static final long serialVersionUID = 237176189403936875L;

	private Long entityId;
	
	private Short abuseType;
	
	private Abuse abuse;
	
	private AbuseManager abuseManager;
	
	public String report(){
		StringBuffer buffer = new StringBuffer();
		buffer.append(ConstantAjax.RETURN_PRE);
		try{
			abuse = new Abuse();
			String url = "";
			if(ConstantDB.ABUSE_TYPE_TOPIC.compareTo(abuseType) == 0){ // 举报帖子
				url = topicReportUrl();
			}
			if(ConstantDB.ABUSE_TYPE_THREAD.compareTo(abuseType) == 0){ // 举报回复
				url = threadReportUrl();
			}
			if(ConstantDB.ABUSE_TYPE_BLOG.compareTo(abuseType) == 0){ //举报博客文章
				url = blogReportUrl();
			}
			abuse  = new Abuse();
			abuse.setAbuseType(abuseType);
			abuse.setAudit(ConstantDB.AUDIT_NONE);
			abuse.setEntity(entityId);
			abuse.setReporter(getUserid());
			abuse.setReportTime(new Date());
			abuse.setUrl(url);
			abuseManager.report(abuse);
			
			buffer.append(ConstantAjax.RESULT_TRUE)
			.append(ConstantAjax.CONTENT_PRE)
			.append(ConstantAjax.ITEM_PRE)
			.append(ConstantAjax.VALUE_PRE)
			.append(getText("common.abuse.success"))
			.append(ConstantAjax.VALUE_SUFF)
			.append(ConstantAjax.POSITION_PRE)
			.append(url)
			.append(ConstantAjax.POSITION_SUFF)
			.append(ConstantAjax.ITEM_SUFF)
			.append(ConstantAjax.CONTENT_SUFF);
			
		}catch(Exception e){
			buffer.append(ConstantAjax.RESULT_FALSE)
			.append(ConstantAjax.CONTENT_PRE)
			.append(getText("common.abuse.error"))
			.append(ConstantAjax.CONTENT_SUFF);
		}
		buffer.append(ConstantAjax.RETURN_SUFF);
		message = buffer.toString();
		return SUCCESS;
	}

	private String topicReportUrl(){
		String url = ConstantUrl.HTML_TOPIC_VIEW + "?tid=" + entityId;
		
		return url;
	}
	private String blogReportUrl(){
		return "";
	}
	private String threadReportUrl(){
		return "";
	}
	public Long getEntityId() {
		return entityId;
	}

	public void setEntityId(Long entityId) {
		this.entityId = entityId;
	}

	public Short getAbuseType() {
		return abuseType;
	}

	public void setAbuseType(Short abuseType) {
		this.abuseType = abuseType;
	}

	public Abuse getAbuse() {
		return abuse;
	}

	public void setAbuse(Abuse abuse) {
		this.abuse = abuse;
	}

	public void setAbuseManager(AbuseManager abuseManager) {
		this.abuseManager = abuseManager;
	}
}
